package com.fr.report.io.xml;

import com.fr.base.core.FRCoreContext;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.core.headerfooter.DateHFElement;
import com.fr.report.core.headerfooter.FormulaHFElement;
import com.fr.report.core.headerfooter.HFElement;
import com.fr.report.core.headerfooter.ImageHFElement;
import com.fr.report.core.headerfooter.ParameterHFElement;
import com.fr.report.core.headerfooter.TextHFElement;
import com.fr.report.parameter.Parameter;

public class HFElementXML
{
  public static void writeXML(XMLPrintWriter paramXMLPrintWriter, HFElement paramHFElement)
  {
    Object localObject;
    paramXMLPrintWriter.startTAG("HFElement").attr("className", paramHFElement.getClass().getName());
    if (paramHFElement instanceof FormulaHFElement)
    {
      localObject = (FormulaHFElement)paramHFElement;
      if (((FormulaHFElement)localObject).getFRFont() != null)
        BaseXMLUtils.writeFRFont(paramXMLPrintWriter, ((FormulaHFElement)localObject).getFRFont());
      if (((FormulaHFElement)localObject).getFormulaContent() != null)
        paramXMLPrintWriter.startTAG("Formula").attr("content", ((FormulaHFElement)localObject).getFormulaContent()).end();
    }
    else if (paramHFElement instanceof DateHFElement)
    {
      localObject = (DateHFElement)paramHFElement;
      if (((DateHFElement)localObject).getFRFont() != null)
        BaseXMLUtils.writeFRFont(paramXMLPrintWriter, ((DateHFElement)localObject).getFRFont());
      if (((DateHFElement)localObject).getFormat() != null)
        ReportXMLUtils.writeFormat(paramXMLPrintWriter, ((DateHFElement)localObject).getFormat());
    }
    else if (paramHFElement instanceof TextHFElement)
    {
      localObject = (TextHFElement)paramHFElement;
      if (((TextHFElement)localObject).getFRFont() != null)
        BaseXMLUtils.writeFRFont(paramXMLPrintWriter, ((TextHFElement)localObject).getFRFont());
      paramXMLPrintWriter.textNode(((TextHFElement)localObject).getText());
    }
    else if (paramHFElement instanceof ImageHFElement)
    {
      localObject = (ImageHFElement)paramHFElement;
      if (((ImageHFElement)localObject).getImage() != null)
        BaseXMLUtils.writeImage(paramXMLPrintWriter, ((ImageHFElement)localObject).getImage());
    }
    paramXMLPrintWriter.end();
  }

  public static HFElement readXML(XMLableReader paramXMLableReader)
  {
    Object localObject;
    HFElement localHFElement = null;
    String str = null;
    if ((str = paramXMLableReader.getAttr("className")) != null)
      try
      {
        localHFElement = (HFElement)FRCoreContext.classForName(str).newInstance();
      }
      catch (Exception localException1)
      {
        try
        {
          localHFElement = (HFElement)FRCoreContext.classForName("com.fr.report.core.headerfooter." + str).newInstance();
        }
        catch (Exception localException2)
        {
        }
      }
    if (localHFElement == null)
      return localHFElement;
    if (localHFElement instanceof DateHFElement)
    {
      localObject = (DateHFElement)localHFElement;
      paramXMLableReader.readXMLObject(new XMLReadable((DateHFElement)localObject)
      {
        private final DateHFElement val$dateHFElement;

        public void readXML(XMLableReader paramXMLableReader)
        {
          if (paramXMLableReader.isChildNode())
          {
            String str = paramXMLableReader.getTagName();
            if (BaseXMLUtils.isFRFontTagName(str))
              this.val$dateHFElement.setFRFont(BaseXMLUtils.readFRFont(paramXMLableReader));
            else if (str.equals("Format"))
              this.val$dateHFElement.setFormat(ReportXMLUtils.readFormat(paramXMLableReader));
          }
        }
      });
    }
    else if (localHFElement instanceof TextHFElement)
    {
      localObject = (TextHFElement)localHFElement;
      2 local2 = new XMLObject(null, (TextHFElement)localObject)
      {
        private final TextHFElement val$textHFElement;

        public void readXML(XMLableReader paramXMLableReader)
        {
          if (paramXMLableReader.isCharacters())
          {
            this.val$textHFElement.setText(paramXMLableReader.getContent());
          }
          else if (paramXMLableReader.isChildNode())
          {
            String str2 = paramXMLableReader.getTagName();
            if (BaseXMLUtils.isFRFontTagName(str2))
            {
              this.val$textHFElement.setFRFont(BaseXMLUtils.readFRFont(paramXMLableReader));
            }
            else if ("Formula".equals(str2))
            {
              String str1;
              if ((str1 = paramXMLableReader.getAttr("content")) != null)
                ((FormulaHFElement)this.val$textHFElement).setFormulaContent(str1);
            }
            else if ("Parameter".equals(str2))
            {
              ((ParameterHFElement)this.val$textHFElement).setParameter(ReportXMLUtils.readParameter(paramXMLableReader));
              this.obj = new FormulaHFElement("=$" + ReportXMLUtils.readParameter(paramXMLableReader).getName());
              ((TextHFElement)this.obj).setText(this.val$textHFElement.getText());
              ((TextHFElement)this.obj).setFRFont(this.val$textHFElement.getFRFont());
            }
          }
        }
      };
      paramXMLableReader.readXMLObject(local2);
      if (local2.getObject() != null)
        localHFElement = (HFElement)local2.getObject();
    }
    else if (localHFElement instanceof ImageHFElement)
    {
      localObject = (ImageHFElement)localHFElement;
      paramXMLableReader.readXMLObject(new XMLReadable((ImageHFElement)localObject)
      {
        private final ImageHFElement val$imageHFElement;

        public void readXML(XMLableReader paramXMLableReader)
        {
          if (paramXMLableReader.getTagName().equals("Image"))
            this.val$imageHFElement.setImage(BaseXMLUtils.readImage(paramXMLableReader));
        }
      });
    }
    return ((HFElement)localHFElement);
  }
}